package com.hunk.core.excel;

import java.util.List;
import java.util.Map;
import java.util.Stack;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

/** Processor Chain
 * 处理链模仿tomcat的FilterChain
 * @author admin
 *
 */
public class ProcessorChain {
	private Stack<Processor> stack = new Stack<Processor>();
	
	public ProcessorChain() {
		super();
	}

	public ProcessorChain(List<Processor> list) {
		super();
		this.stack.addAll(list);
	}

	public String process(HSSFWorkbook hssfWorkbook, HSSFSheet hssfSheet,
			HSSFRow hssfRow,HSSFCell hssfCell, Map<String,String> entity, 
			String stringValue, ProcessorChain chain){		
		if (stack.size() == 0) {
			return stringValue;
		}
		Processor processor = stack.pop();
		return processor.process(hssfWorkbook, hssfSheet, hssfRow, hssfCell, entity, stringValue, this);
	}
	
	public void addProcessor(Processor processor) {
		stack.push(processor);
	}
	
	public void addProcessors(List<Processor> processors) {
		stack.addAll(processors);
	}
}
